import crypto from 'crypto'
export class cryptoUtil {
    // aes-128 对应 16字节 16*8
    static readonly KEY:string = 'abcdef1234567890'
    // aes-128 对应 16字节 16*8
    static readonly IV: string = 'jklmno1234567890'
    constructor() {}
    // aes对称加密
    encrypt(key: string, iv: string, text: string) {
        const dep = crypto.createCipheriv('aes-128-ocb', key, iv);
        return dep.update(text, 'binary', 'hex') + dep.final('hex');
    }
    // aes对称解密
    decrypt(key: string, iv: string, crypted: string) {
        crypted = Buffer.from(crypted, 'hex').toString('binary');
        const dep = crypto.createDecipheriv('aes-128-ocb', key, iv);
        return dep.update(crypted, 'binary', 'utf-8');
    }
}